

import java.util.*;



public class HTMLSalesFormatter implements SalesFormatter{
    private static HTMLSalesFormatter singletonInstance=null;
    private HTMLSalesFormatter(){ }
    public static HTMLSalesFormatter getSingletonInstance(){
        if(singletonInstance==null){
            singletonInstance=new HTMLSalesFormatter();
        }
        return singletonInstance;
    }
   

    public String formatSales(Sales sales){
        
        String str="";
        str=str+"\n"+" <html>"+"\n"+"   <body>"+"\n"+"  <center><h2>Orders</h2></center>";
        Order order;
        for(Iterator<Order> a=sales.iterator();a.hasNext();){
            order=(Order)a.next();
            StringBuilder str1=(new StringBuilder().append("\n"+"<hr>"+"\n"+"<h4>Total = "+order.getTotalCost()+" </h4>"));
            OrderItem item;
            for(Iterator<OrderItem> b=order.iterator();b.hasNext();){
                item=(OrderItem)b.next();
                str1=str1.append("\n"+"<p>"+"\n"+"  <b>code:</b> "+item.getProduct().getCode()+" <br>");
                str1=str1.append("\n"+"  <b>quantity:</b> "+item.getQuantity()+" <br>");
                str1=str1.append("\n"+"  <b>price:</b> "+item.getProduct().getPrice()+"\n"+"</p>");
            }
            str=str+str1.toString();
        }
        return str;
    }
}

